package net.bwie.realtime.warehouse.DWS;

import org.apache.flink.table.functions.ScalarFunction;

/**
 * @BelongsProject: realtime-project-10zlq
 * @BelongsPackage: net.bwie.realtime.warehouse.DWS
 * @Author: zhangleqing
 * @CreateTime: 2025-09-02  11:40
 * @Description: TODO
 * @Version: 1.0
 */
public class RegExpInstrFunction extends ScalarFunction {
    public int eval(String text, String regex) {
        if (text == null || regex == null) {
            return 0;
        }
        java.util.regex.Pattern pattern = java.util.regex.Pattern.compile(regex);
        java.util.regex.Matcher matcher = pattern.matcher(text);
        if (matcher.find()) {
            return matcher.start() + 1; // SQL 中索引从 1 开始
        }
        return 0;
    }
}
